package com.zide.system.controller;

import com.zide.common.constant.Constants;
import com.zide.common.core.domain.CommonResult;
import com.zide.common.core.domain.model.LoginBody;
import com.zide.system.service.SysLoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 石添
 * @date 2024/2/26 10:32
 */
@Tag(name = "管理后台 - 用户认证管理")
@RequestMapping("/admin/auth")
@RestController
public class AuthController {

    @Resource
    private SysLoginService loginService;

    @Operation(summary = "登录方法")
    @PostMapping("/login")
    public CommonResult login(@RequestBody LoginBody loginBody) {
        CommonResult ajax = CommonResult.success();
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
                loginBody.getUuid());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    @Operation(summary = "登出方法")
    @GetMapping("/logout")
    public CommonResult logout() {
        return  CommonResult.success();
    }
}
